package server

import (
	"context"
	"errors"
	"user_server/pkg"
	pb "user_server/proto"
)

type Servers struct {
	pb.UnimplementedUserServer
}

func (s *Servers) UserLogin(c context.Context, req *pb.UserLoginReq) (*pb.UserLoginResp, error) {
	user := User{
		Username: req.Username,
		Password: pkg.PwdMd5(req.Password),
	}
	id, message := user.UserLogins()
	if message != "" {
		return &pb.UserLoginResp{Id: 0}, errors.New(message)
	}
	return &pb.UserLoginResp{Id: int64(id)}, nil
}
